﻿using Server.Framework.Socket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Service
{
    /// <summary>
    /// Author: Leil
    /// Description: UserService
    /// CreateTime: 2020/6/15 11:10:25
    /// </summary>
    public class UserService
    {
        private static readonly object obj = new object();
        private static UserService instance;

        private UserService() { }

        public static UserService Instance()
        {
            if (instance == null) { 
                lock(obj)
                {
                    if (instance == null)
                    {
                        instance = new UserService();
                    }
                }
            }
            return instance;
        }

        private readonly Dictionary<int, ProtobufAppSession> userSessionDic = new Dictionary<int, ProtobufAppSession>();

        public void AddUserSession(int id, ProtobufAppSession session)
        {
            if(!userSessionDic.ContainsKey(id))
            {
                userSessionDic.Add(id, session);
            }
        }


        public void RemoveUserSession(int id)
        {
            if (userSessionDic.ContainsKey(id))
            {
                userSessionDic.Remove(id);
            }
        }


        public bool HasUserSession(int id)
        {
            return userSessionDic.ContainsKey(id);
        }




    }
}
